package news.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import news.dao.impl.NewsDaoImpl;
import news.dao.impl.UserDaoImpl;
import news.entity.News;
import news.entity.User;

import org.news.dao.NewsDao;

public class DoLogin extends HttpServlet {

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		this.doPost(request, response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=UTF-8");
		String uname = request.getParameter("uname");
		String password = request.getParameter("upwd");
		String autologin = request.getParameter("autologin");
		UserDaoImpl ud = new UserDaoImpl();
		User user = ud.findUser(uname, password);
		request.getSession().setAttribute("user", user);
		request.getRequestDispatcher("do_login.jsp").forward(request, response);
	}
}
